from flask import jsonify


class HttpCode(object):
    ok = 200
    auth_error_code = 401
    params_error_code = 400
    maintain_error_code = 402
    server_error_code = 500


def restful_result(code, message, data):
    return jsonify({"code": code, "message": message, "data": data or {}})


def success(message="", data=None):
    return restful_result(code=HttpCode.ok, message=message, data=data)


def table_success(message="", data=None, count=0):
    return jsonify({"code": 0, "message": message, "data": data or {}, "count": count})


def auth_error(message=""):
    return restful_result(code=HttpCode.auth_error_code, message=message, data=None)


def params_error(message=""):
    return restful_result(code=HttpCode.params_error_code, message=message, data=None)


def maintain_error(message=""):
    return restful_result(code=HttpCode.maintain_error_code, message=message, data=None)


def server_error(message=""):
    return restful_result(code=HttpCode.server_error_code, message=message or '网络异常', data=None)
